#pragma once
#ifdef WIN32
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif

#include<string>
#include<list>
#include<vector>
#include "json.hpp"
using json = nlohmann::json;
struct tilebox
{
	std::vector<double> max;
	std::vector<double> min;
	void extend(double ratio) {
		        ratio /= 2;
		        double x = max[0] - min[0];
		        double y = max[1] - min[1];
		        double z = max[2] - min[2];
		        max[0] += x * ratio;
		        max[1] += y * ratio;
		        max[2] += z * ratio;
		
		        min[0] -= x * ratio;
		        min[1] -= y * ratio;
		        min[2] -= z * ratio;
		    }
};
//
//struct osgtree {
//	tile_box bbox;
//	std::string file_name;
//	std::vector<osgtree> sub_nodes;
//};

struct Asset
{
	std::string version;
	std::string gltfUpAxis;
};

void to_json(json& j, const Asset& p);

void from_json(const json& j, Asset& p);

struct BoundingVolume
{
	std::vector<double> box;
};

void to_json(json & j, const BoundingVolume & p);

void from_json(const json & j, BoundingVolume & p);


struct Content {
	std::string uri;
};
struct Tile {
	tilebox bbox;
	BoundingVolume boundingVolume;
	double geometricError;
	Content content;
	std::vector<Tile> children;
};
void to_json(json& j, const Tile& p);

void from_json(const json& j, Tile& p);


struct Root
{
	BoundingVolume boundingVolume;
	double geometricError;
	std::vector<double> transform;
	std::list<Tile> children;
};

void to_json(json& j, const Root& p);

void from_json(const json& j, Root& p);

struct TileSet
{
	Asset asset;
	double geometricError;
	Root root;
};

void to_json(json& j, const TileSet& p);

void from_json(const json& j, TileSet& p);

extern "C" {
	DLL_API Tile  osgb23dtile_path(const char* in_path, const char* infilename, const char* out_path, double *box, double x, double y, int max_lvl);


	DLL_API void transform_c(double center_x, double center_y, double height_min, double* ptr);
}
